﻿#define _CRT_SECURE_NO_WARNINGS 1
//搜索旋转排序数组中的最⼩值（medium）:https://leetcode.cn/problems/find-minimum-in-rotated-sorted-array/submissions/517954900/

class Solution {
public:
    int findMin(vector<int>& nums) {
        int left = 0, right = nums.size() - 1;

        if (nums[left] < nums[right])
        {
            return nums[left];
        }

        while (left < right)
        {
            int mid = left + (right - left) / 2;
            if (nums[mid] < nums[right])
            {
                right = mid;
            }
            else
            {
                left = mid + 1;
            }
        }

        return nums[left];
    }
};


//0〜n-1 中缺失的数字（easy）:https://leetcode.cn/problems/que-shi-de-shu-zi-lcof/

class Solution {
public:
    int takeAttendance(vector<int>& records) {
        int n = records.size();
        int left = 0, right = n - 1;
        //int left=0,right=n;
        while (left < right)
        {
            int mid = left + (right - left) / 2;
            if (records[mid] != mid)
            {
                right = mid;
            }
            else
            {
                left = mid + 1;
            }
        }

        return left == n - 1 && records[left] == left ? n : left;
        //return left;
    }
};